//
//  M1IdCardCerVC.m
//  NewMarryU
//
//  Created by apple on 2018/7/13.
//  Copyright © 2018年 Cedar. All rights reserved.
//

#import "M1IdCardCerVC.h"
#import "M1CerViewController.h"
@interface M1IdCardCerVC ()
@property (nonatomic ,strong) UIView *m1_phtoView;
@property (nonatomic ,strong) UIButton *m1_addBtn;
@property (nonatomic ,strong) NSMutableArray *m1_images;
@end

@implementation M1IdCardCerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"身份信息";
    [self m1_createUI];
}
-(void)m1_commit{
    M1CerViewController *m1_cerVC = [[M1CerViewController alloc]init];
    [self.navigationController pushViewController:m1_cerVC animated:YES];
}

-(void)m1_tgClick{
    
}

-(void)m1_addBtnClicl{
    M1SheetView *m1_sheet = [[M1SheetView alloc]initWithTitles:@[@"拍照",@"从相册选择"]];
    [m1_sheet m1_show];
    
    WEAKSELF;
    m1_sheet.click = ^(NSInteger index) {
        [[M1ImagePick manager] m1_pickImages:^(NSArray *photos) {
            
        } type:index maxCount:2 vc:weakSelf];
    };
}

-(void)m1_setImageView{
    float with = (SCREENWIDTH-75)/2.;
    for (UIView *view in _m1_phtoView.subviews) {
        [view removeFromSuperview];
    }
    for (int i = 0; i<_m1_images.count; i++) {
        UIImageView *m1_view = [[UIImageView alloc]init];
        m1_view.image = _m1_images[i];
        m1_view.backgroundColor = [UIColor m1_colorHex:0xE6E6E6];
        m1_view.contentMode = UIViewContentModeScaleAspectFill;
        m1_view.layer.cornerRadius = 10;
        m1_view.clipsToBounds = YES;
        [_m1_phtoView addSubview:m1_view];
        [m1_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset((with+10)*i);
            make.top.offset(25);
            make.size.mas_offset(CGSizeMake(with, with*0.67));
        }];
    }
    
    if (_m1_images.count ==1 ) {
        [_m1_phtoView addSubview:self.m1_addBtn];
        [self.m1_addBtn mas_makeConstraints:^(MASConstraintMaker *make) {

            make.left.offset((with+10)*_m1_images.count);
            make.top.offset(0);
            make.size.mas_offset(CGSizeMake(with, with*0.67));

        }];
    }
    
    if (_m1_images.count ==0 ) {
        [_m1_phtoView addSubview:self.m1_addBtn];
        [self.m1_addBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.offset(0);
            make.top.offset(0);
            make.size.mas_offset(CGSizeMake(with, with*0.67));
            
        }];
    }
    
}
- (UIButton *)m1_addBtn{
    if (!_m1_addBtn) {
        _m1_addBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_m1_addBtn setBackgroundImage:[UIImage imageNamed:@"login_id_add"] forState:0];
        [_m1_addBtn addTarget:self action:@selector(m1_addBtnClicl) forControlEvents:UIControlEventTouchUpInside];
    }
    return _m1_addBtn;
}

-(void)m1_createUI{
    _m1_images = [NSMutableArray arrayWithCapacity:0];
    UIScrollView *m1_scroll = [[UIScrollView alloc]init];
    m1_scroll.showsVerticalScrollIndicator = NO;
    m1_scroll.showsHorizontalScrollIndicator = NO;
    [self.view addSubview:m1_scroll];
    if (@available(iOS 11.0, *)) {
        m1_scroll.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [m1_scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.right.offset(0);
        make.top.offset(iPhoneX?88:64);
        make.bottom.offset(0);
    }];UIView *m1_bgView = [[UIView alloc]init];
    m1_bgView.layer.shadowColor = [UIColor m1_colorHex:0xCAD0DC].CGColor;
    m1_bgView.layer.shadowOpacity = 0.25;
    m1_bgView.layer.shadowOffset = CGSizeMake(1, 1);
    m1_bgView.layer.cornerRadius = 13;
    m1_bgView.backgroundColor = [UIColor whiteColor];
    [m1_scroll addSubview:m1_bgView];
    
    [m1_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.equalTo(self.view.mas_right).offset(-20);
        make.top.equalTo(m1_scroll.mas_top).offset(iPhoneX?20:(iPhone5?0:20));
    }];
    
    UIImageView *m1_imgView1 = [[UIImageView alloc]init];
    m1_imgView1.image = [UIImage imageNamed:@"login_ds"];
    [m1_bgView addSubview:m1_imgView1];
    [m1_imgView1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.offset(20);
    }];
    
    UILabel *m1_LB1 = [[UILabel alloc]init];
    m1_LB1.font  =m1_boldFont(18);
    m1_LB1.text = @"为什么要身份认证？";
    m1_LB1.textColor = [UIColor m1_colorHex:0x333333];
    [m1_bgView addSubview:m1_LB1];
    [m1_LB1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(m1_imgView1.mas_centerY);
        make.left.offset(45);
    }];
    
    
    UILabel *m1_LB2 = [[UILabel alloc]init];
    m1_LB2.font  =m1_font(15);
    m1_LB2.numberOfLines = 0;
    m1_LB2.text = @"MarryU作为一个真实、严肃的婚恋俱乐部，我们要求用户必须完成身份认证。对于以结婚为目的的用户，我们希望提供他们一个无酒托、婚托的婚恋环境。";
    m1_LB2.textColor = [UIColor m1_colorHex:0xB3B3B3];
    [m1_bgView addSubview:m1_LB2];
    [m1_LB2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(m1_LB1.mas_bottom).offset(15);
        make.left.equalTo(m1_LB1.mas_left);
        make.right.offset(-30);
    }];
    
    UIImageView *m1_imgView2 = [[UIImageView alloc]init];
    m1_imgView2.image = [UIImage imageNamed:@"login_cs"];
    [m1_bgView addSubview:m1_imgView2];
    [m1_imgView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(m1_LB2.mas_bottom).offset(25);
    }];
    
    UILabel *m1_LB3 = [[UILabel alloc]init];
    m1_LB3.font  =m1_boldFont(18);
    m1_LB3.text = @"关于隐私安全";
    m1_LB3.textColor = [UIColor m1_colorHex:0x333333];
    [m1_bgView addSubview:m1_LB3];
    [m1_LB3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(m1_imgView2.mas_centerY);
        make.left.offset(45);
    }];
    
    UILabel *m1_LB4 = [[UILabel alloc]init];
    m1_LB4.font  =m1_font(15);
    m1_LB4.numberOfLines = 0;
    m1_LB4.text = @"您上传的任何身份证照片等资料，仅供参和使用并且TA人无法查看，敬请放心。";
    m1_LB4.textColor = [UIColor m1_colorHex:0xB3B3B3];
    [m1_bgView addSubview:m1_LB4];
    [m1_LB4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(m1_LB3.mas_bottom).offset(15);
        make.left.equalTo(m1_LB1.mas_left);
        make.right.offset(-30);
    }];
    
    UILabel *m1_LB5 = [[UILabel alloc]init];
    m1_LB5.font  =m1_boldFont(18);
    m1_LB5.text = @"身份认证";
    m1_LB5.textColor = [UIColor m1_colorHex:0x333333];
    [m1_bgView addSubview:m1_LB5];
    [m1_LB5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(m1_LB4.mas_bottom).offset(25);
        make.left.equalTo(m1_imgView1.mas_left);
    }];
    
    UILabel *m1_LB6 = [[UILabel alloc]init];
    m1_LB6.font = m1_font(14);
    m1_LB6.text = @"（请务必按样例上传照片）";
    m1_LB6.textColor = [UIColor m1_colorHex:0x999999];
    [m1_bgView addSubview:m1_LB6];
    [m1_LB6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(m1_LB5.mas_centerY);
        make.left.equalTo(m1_LB5.mas_right).offset(10);
    }];
    
    float with = (SCREENWIDTH-75)/2.;
    NSArray *array = @[@"login_id_z",@"login_id_f"];
    NSArray *array1 = @[@"手持身份证正面照",@"身份证正面照"];
    for (int i = 0; i<array.count; i++) {
        UIImageView *m1_view = [[UIImageView alloc]init];
        m1_view.image = [UIImage imageNamed:array[i]];
        m1_view.backgroundColor = [UIColor m1_colorHex:0xE6E6E6];
        m1_view.layer.cornerRadius = 10;
        m1_view.clipsToBounds = YES;
        [m1_bgView addSubview:m1_view];
        [m1_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(15+(with+10)*i);
            make.top.equalTo(m1_LB5.mas_bottom).offset(25);
            make.size.mas_offset(CGSizeMake(with, with*0.67));
        }];
        
        UILabel *m1_LB7 = [[UILabel alloc]init];
        m1_LB7.textColor = [UIColor m1_colorHex:0x999999];
        m1_LB7.font = m1_font(12);
        m1_LB7.text = array1[i];
        [m1_bgView addSubview:m1_LB7];
        [m1_LB7 mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(m1_view.mas_bottom).offset(15);
            make.centerX.equalTo(m1_view.mas_centerX);
        }];
    }
    
    _m1_phtoView = [[UIView alloc]init];
    [m1_bgView addSubview:_m1_phtoView];
    [_m1_phtoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.right.offset(-15);
        make.height.mas_offset(with*0.67);
        make.top.equalTo(m1_LB5.mas_bottom).offset(67+with*0.67);
        make.bottom.offset(-30);
    }];
    
    UIImage *m1_bgImg = [UIImage imageNamed:@"btn_color"];
    UIButton *m1_commitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [m1_commitBtn setTitle:@"提交" forState:0];
    [m1_commitBtn setBackgroundImage:m1_bgImg  forState:0];
    m1_commitBtn.imageView.contentMode = UIViewContentModeScaleAspectFill;
    [m1_commitBtn setTitleColor:[UIColor whiteColor] forState:0];
    m1_commitBtn.titleLabel.font = m1_font(16);
    m1_commitBtn.layer.cornerRadius = 25;
    m1_commitBtn.clipsToBounds = YES;
    [m1_commitBtn addTarget:self action:@selector(m1_commit) forControlEvents:UIControlEventTouchUpInside];
    [m1_scroll addSubview:m1_commitBtn];
    [m1_commitBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(m1_bgView.mas_bottom).offset(30);
        make.size.mas_offset(CGSizeMake(270, 50));
    }];
    
    UIButton *m1_tgBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [m1_tgBtn setTitle:@"证件照不在身边？暂时跳过" forState:0];
    [m1_tgBtn setTitleColor:[UIColor whiteColor] forState:0];
    m1_tgBtn.titleLabel.font = m1_font(16);
    m1_tgBtn.layer.cornerRadius = 25;
    m1_tgBtn.clipsToBounds = YES;
    m1_tgBtn.backgroundColor = m1_line_color;
     [m1_commitBtn addTarget:self action:@selector(m1_tgClick) forControlEvents:UIControlEventTouchUpInside];
    [m1_scroll addSubview:m1_tgBtn];
    [m1_tgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.view);
        make.top.equalTo(m1_commitBtn.mas_bottom).offset(20);
        make.size.mas_offset(CGSizeMake(270, 50));
        make.bottom.equalTo(m1_scroll.mas_bottom).offset(-40);
    }];
    
    [self m1_setImageView];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
